home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / FWPxyFrm.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  23.6 KB  |  783 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWPxyFrm.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWPXYFRM_H
  13. #include "FWPxyFrm.h"
  14. #endif
  15.  
  16. #ifndef FWPARTNG_H
  17. #include "FWPartng.h"
  18. #endif
  19.  
  20. #ifndef FWFRMING_H
  21. #include "FWFrming.h"
  22. #endif
  23.  
  24. #ifndef FWPROXY_H
  25. #include "FWProxy.h"
  26. #endif
  27.  
  28. #ifndef FWUTIL_H
  29. #include "FWUtil.h"
  30. #endif
  31.  
  32. #ifndef FWCLNINF_H
  33. #include "FWClnInf.h"
  34. #endif
  35.  
  36. #ifndef FWPXYITE_H
  37. #include "FWPxyIte.h"
  38. #endif
  39.  
  40. // ----- OS Layer -----
  41.  
  42. #ifndef FWBARRAY_H
  43. #include "FWBArray.h"
  44. #endif
  45.  
  46. #ifndef FWGRUTIL_H
  47. #include "FWGrUtil.h"
  48. #endif
  49.  
  50. #ifndef FWODGEOM_H
  51. #include "FWODGeom.h"
  52. #endif
  53.  
  54. // ----- Foundation Layer -----
  55.  
  56. #ifndef FWSOMENV_H
  57. #include "FWSOMEnv.h"
  58. #endif
  59.  
  60. // ----- OpenDoc Includes -----
  61.  
  62. #ifndef SOM_ODFrame_xh
  63. #include <Frame.xh>
  64. #endif
  65.  
  66. #ifndef SOM_ODFacet_xh
  67. #include <Facet.xh>
  68. #endif
  69.  
  70. #ifndef SOM_Module_OpenDoc_StdProps_defined
  71. #include <StdProps.xh>
  72. #endif
  73.  
  74. #ifndef SOM_ODStorageUnitView_xh
  75. #include <SUView.xh>
  76. #endif
  77.  
  78. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  79. #include <StdTypes.xh>
  80. #endif
  81.  
  82. #ifndef SOM_ODEmbeddedFramesIterator_xh
  83. #include <EmbFrItr.xh>
  84. #endif
  85.  
  86. #ifndef SOM_ODTransform_xh
  87. #include <Trnsform.xh>
  88. #endif
  89.  
  90. #ifndef SOM_ODDraft_xh
  91. #include <Draft.xh>
  92. #endif
  93.  
  94. //========================================================================================
  95. //    RunTime Info
  96. //========================================================================================
  97.  
  98. #ifdef FW_BUILD_MAC
  99. #pragma segment fw_embedding2
  100. #endif
  101.  
  102.  
  103. //========================================================================================
  104. //    Template Instantiations
  105. //========================================================================================
  106.  
  107. FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollectionIterator, FW_CProxyFrame)
  108. FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollection, FW_CProxyFrame)
  109.  
  110. #ifdef FW_USE_TEMPLATE_PRAGMAS
  111.  
  112. #pragma template_access public
  113. #pragma template FW_TOrderedCollection<FW_CProxyFrame>
  114. #pragma template FW_TOrderedCollectionIterator<FW_CProxyFrame>
  115.  
  116. #endif
  117.  
  118. //========================================================================================
  119. //    class FW_CProxyFrame
  120. //========================================================================================
  121.  
  122. //----------------------------------------------------------------------------------------
  123. //    FW_CProxyFrame::FW_CProxyFrame
  124. //----------------------------------------------------------------------------------------
  125.  
  126. FW_CProxyFrame::FW_CProxyFrame(Environment* ev, 
  127.                                 FW_MProxy* proxy,
  128.                                 FW_CEmbeddingPart* part) :
  129.     fPart(part),
  130.     fProxy(proxy),
  131.     fFrameID(kODNULLID),
  132.     fContainingFrameID(kODNULLID),
  133.     fEmbeddedFrame(NULL),
  134.     fPurgeable(FALSE),
  135.     fHasBeenInstantiated(FALSE),
  136.     fAttached(TRUE),
  137.     fFrameDraft(NULL),
  138.     fWasInLimbo(FALSE),
  139.     fWasDragged(FALSE),
  140.     fFacetCount(0),
  141.     fHighlight(kODNoHighlight),
  142.     fLinkStatus(kODNotInLink)
  143. {
  144. FW_UNUSED(ev);
  145.     FW_ASSERT(fPart != NULL);
  146. }
  147.  
  148. //----------------------------------------------------------------------------------------
  149. //    FW_CProxyFrame::FW_CProxyFrame
  150. //----------------------------------------------------------------------------------------
  151.  
  152. FW_CProxyFrame::FW_CProxyFrame(Environment* ev, 
  153.                                 FW_MProxy* proxy,
  154.                                 FW_CEmbeddingPart* part, 
  155.                                 FW_CEmbeddingFrame* containingFrame, 
  156.                                 ODFrame* embeddedFrame,
  157.                                 FW_Boolean wasInLimbo) :
  158.     fPart(part),
  159.     fProxy(proxy),
  160.     fFrameID(kODNULLID),
  161.     fContainingFrameID(kODNULLID),
  162.     fEmbeddedFrame(embeddedFrame),
  163.     fPurgeable(FALSE),
  164.     fHasBeenInstantiated(TRUE),
  165.     fAttached(TRUE),
  166.     fFrameDraft(NULL),
  167.     fWasInLimbo(wasInLimbo),
  168.     fWasDragged(FALSE),
  169.     fFacetCount(0),
  170.     fHighlight(kODNoHighlight),
  171.     fLinkStatus(kODNotInLink)
  172. {
  173.     FW_ASSERT(fPart != NULL);
  174.     FW_ASSERT(fProxy != NULL);
  175.     FW_ASSERT(containingFrame != NULL);
  176.     FW_ASSERT(fEmbeddedFrame != NULL);
  177.     FW_ASSERT(containingFrame->GetPart(ev) == part);
  178.     
  179.     fEmbeddedFrame->Acquire(ev);
  180.     fFrameID = fEmbeddedFrame->GetID(ev);
  181.  
  182.     // ----- Save embedded frame's draft if persistent frame
  183.     ODStorageUnit* frameSU = fEmbeddedFrame->GetStorageUnit(ev);
  184.     if (frameSU != NULL)
  185.         fFrameDraft = frameSU->GetDraft(ev);
  186.     
  187.     fContainingFrameID = containingFrame->GetID(ev);
  188.  
  189. #ifdef FW_DEBUG
  190.     {
  191.         FW_CAcquiredODFrame aqContainingFrame = embeddedFrame->AcquireContainingFrame(ev);
  192.         FW_ASSERT(aqContainingFrame == containingFrame->GetODFrame(ev));
  193.     }
  194. #endif
  195.  
  196.     // ----- If the frame was in Limbo -----
  197.     embeddedFrame->SetInLimbo(ev, FALSE);
  198. }
  199.  
  200. //----------------------------------------------------------------------------------------
  201. //    FW_CProxyFrame::~FW_CProxyFrame
  202. //----------------------------------------------------------------------------------------
  203.  
  204. FW_CProxyFrame::~FW_CProxyFrame()
  205. {
  206.     // [HLX] Need a try block
  207.     if (fEmbeddedFrame)
  208.     {
  209.         FW_SOMEnvironment ev;
  210.         if (!FW_IsInLimbo(ev, fEmbeddedFrame))    // [HLX] do not call ODFrame::IsInLimbo. see FW_IsInLimbo
  211.             fEmbeddedFrame->Release(ev);
  212.         else
  213.         {
  214.             // If the embedded frame doesn't have fContainingFrameID as containing frame then 
  215.             // doesn't remove
  216.             FW_CAcquiredODFrame embeddingFrame = fEmbeddedFrame->AcquireContainingFrame(ev);
  217.             if (embeddingFrame == NULL || embeddingFrame->GetID(ev) == fContainingFrameID)
  218.             {
  219.                 if (fWasInLimbo)
  220.                     fEmbeddedFrame->Release(ev);
  221.                 else
  222.                     fEmbeddedFrame->Remove(ev);
  223.             }
  224.             else
  225.                 fEmbeddedFrame->Release(ev);
  226.         }
  227.     }
  228.     FW_ASSERT(fFacetCount == 0);
  229. }
  230.  
  231. //----------------------------------------------------------------------------------------
  232. //    FW_CProxyFrame::GetContainingFrame
  233. //----------------------------------------------------------------------------------------
  234. //    GetContainingFrame returns null if the containing frame of this proxyframe is not a valid 
  235. //    display frame
  236.  
  237. FW_CEmbeddingFrame* FW_CProxyFrame::GetContainingFrame(Environment* ev) const
  238. {
  239.     FW_CProxyFrame* self = (FW_CProxyFrame*)this;
  240.     
  241.     if (fPart->IsValidDisplayFrame(ev, fContainingFrameID))
  242.     {
  243.         FW_CAcquiredODFrame aqContainingODFrame =  fPart->GetDraft(ev)->AcquireFrame(ev, fContainingFrameID);
  244.  
  245.         FW_CEmbeddingFrame* containingFrame = FW_CEmbeddingFrame::ODtoFWEmbeddingFrame(ev, aqContainingODFrame);
  246.         FW_ASSERT(containingFrame != NULL);
  247.     
  248.         return containingFrame;
  249.     }
  250.     
  251.     return NULL;
  252. }
  253.  
  254. //----------------------------------------------------------------------------------------
  255. //    FW_CProxyFrame::GetFrame
  256. //----------------------------------------------------------------------------------------
  257.  
  258. ODFrame* FW_CProxyFrame::GetFrame(Environment* ev) const
  259. {
  260.     if (fEmbeddedFrame == NULL)
  261.     {
  262.         FW_ASSERT(fFrameDraft != NULL);
  263.         
  264.         FW_CProxyFrame* self = (FW_CProxyFrame*)this;
  265.         
  266.         self->fEmbeddedFrame = fFrameDraft->AcquireFrame(ev, fFrameID);
  267.         self->fHasBeenInstantiated = TRUE;
  268.  
  269.         if (fAttached)
  270.         {
  271.             fEmbeddedFrame->SetInLimbo(ev, FALSE);    // Just in case
  272.             
  273.             if (!this->IsOrphan(ev))
  274.                 this->PrivChangeLinkStatus(ev);
  275.         }
  276.             
  277.         FW_ASSERT(fEmbeddedFrame != NULL);
  278.     }
  279.     
  280.     return fEmbeddedFrame;
  281. }
  282.  
  283. //----------------------------------------------------------------------------------------
  284. //    FW_CProxyFrame::SetPurgeable
  285. //----------------------------------------------------------------------------------------
  286.  
  287. void FW_CProxyFrame::SetPurgeable(Environment* ev, FW_Boolean purgeable)
  288. {        
  289.     if (fPurgeable == purgeable)
  290.         return;
  291.         
  292.     fPurgeable = purgeable;
  293.     
  294.     if (!fPurgeable)
  295.     {
  296.         GetFrame(ev);    // to be sure that the frame is in memory
  297.  
  298.         // ----- Create facets for the new frame if they have been purged -----
  299.         FW_ASSERT(fPart->IsValidDisplayFrame(ev, fContainingFrameID));
  300.         CreateAllFacets(ev);    // Will test if needs facets
  301.     }
  302. }
  303.  
  304. //----------------------------------------------------------------------------------------
  305. //    FW_CProxyFrame::PrivClose
  306. //----------------------------------------------------------------------------------------
  307.  
  308. void FW_CProxyFrame::PrivClose(Environment* ev)
  309. {
  310.     if (fHasBeenInstantiated)
  311.     {
  312.         GetFrame(ev);                    // So we are sure it is in memory
  313.         FW_ASSERT(fEmbeddedFrame);
  314.         fEmbeddedFrame->Close(ev);        // Will call release    
  315.     }
  316.     
  317.     fEmbeddedFrame = NULL;
  318. }
  319.  
  320. //----------------------------------------------------------------------------------------
  321. //    FW_CProxyFrame::Release
  322. //----------------------------------------------------------------------------------------
  323.  
  324. void FW_CProxyFrame::Release(Environment* ev)
  325. {
  326.     if (fEmbeddedFrame != NULL)
  327.         fEmbeddedFrame->Release(ev);
  328.     fEmbeddedFrame = NULL;
  329. }
  330.  
  331. //----------------------------------------------------------------------------------------
  332. //    FW_CProxyFrame::Purge
  333. //----------------------------------------------------------------------------------------
  334.  
  335. ODSize FW_CProxyFrame::Purge(Environment* ev)
  336. {
  337.     if (!IsFrameInMemory(ev))
  338.         return 0;                // already gone
  339.         
  340.     // [HLX] I am not sure about that. If purge is called in a middle of a drag&drop I
  341.     // may not be the owner of this frame anymore ????
  342.     FW_CAcquiredODFrame aqODContainingFrame = fEmbeddedFrame->AcquireContainingFrame(ev);
  343.     FW_CAcquiredODPart aqODContainingPart = aqODContainingFrame->AcquirePart(ev);
  344.     if (aqODContainingPart != fPart->GetODPart(ev))
  345.         fPurgeable = FALSE;
  346.     
  347.     if (fPurgeable)
  348.     {        
  349.         // ----- Remove its facets
  350.         FW_ASSERT(fPart->IsValidDisplayFrame(ev, fContainingFrameID));
  351.         this->RemoveAllFacets(ev);
  352.         
  353.         // ----- Now I can release the frame
  354.         Release(ev);
  355.         
  356.         return 1;
  357.     }
  358.     
  359.     return 0;
  360. }
  361.  
  362. //----------------------------------------------------------------------------------------
  363. //    FW_CProxyFrame::InternalizeProxyFrame
  364. //----------------------------------------------------------------------------------------
  365. //    returns true if valid 
  366.  
  367. FW_Boolean FW_CProxyFrame::InternalizeProxyFrame(Environment* ev, ODStorageUnitView* suView, FW_CCloneInfo* cloneInfo)
  368. {
  369.     ODStorageUnitRef aSURef;    
  370.     FW_CByteArray byteArray;
  371.         
  372.     // ----- Read reference -----
  373.     suView->GetValue(ev, sizeof(ODStorageUnitRef), byteArray);
  374.     byteArray.CopyBuffer(&aSURef, sizeof(ODStorageUnitRef));
  375.     
  376.     if (!suView->IsValidStorageUnitRef(ev, aSURef))
  377.         return FALSE;
  378.     
  379.     ODStorageUnitID fromFrameID = suView->GetIDFromStorageUnitRef(ev, aSURef);
  380.  
  381.     if (cloneInfo != NULL)
  382.     {
  383.         // ----- We are cloning -----
  384.         fFrameID = cloneInfo->Clone(ev, fromFrameID, 0, 0);
  385.         fFrameDraft = cloneInfo->GetToDraft(ev);
  386.         
  387.         fContainingFrameID = cloneInfo->GetScopeFrame(ev)->GetID(ev);
  388.     }
  389.     else
  390.     {
  391.         // ----- Save the frame's draft
  392.         fFrameDraft = suView->GetStorageUnit(ev)->GetDraft(ev);
  393.         
  394.         // ----- Cache the id of the containing frame -----
  395.         FW_CAcquiredODStorageUnit aqFrameSU = fFrameDraft->AcquireStorageUnit(ev, fromFrameID);
  396.         aqFrameSU->Focus(ev, kODPropContainingFrame, kODPosUndefined, kODWeakStorageUnitRef, 0, kODPosUndefined);
  397.         
  398.         aqFrameSU->GetValue(ev, sizeof(ODStorageUnitRef), byteArray);
  399.         byteArray.CopyBuffer(&aSURef, sizeof(ODStorageUnitRef));
  400.  
  401.         if (aqFrameSU->IsValidStorageUnitRef(ev, aSURef))
  402.             fContainingFrameID = aqFrameSU->GetIDFromStorageUnitRef(ev, aSURef);
  403.         else
  404.             fContainingFrameID = kODNULLID;
  405.  
  406.         // ----- Now we can set the frame ID -----
  407.         fFrameID = fromFrameID;
  408.     }
  409.         
  410.     return TRUE;
  411. }
  412.  
  413. //----------------------------------------------------------------------------------------
  414. //    FW_CProxyFrame::ExternalizeProxyFrame
  415. //----------------------------------------------------------------------------------------
  416.  
  417. FW_Boolean FW_CProxyFrame::ExternalizeProxyFrame(Environment* ev, ODStorageUnitView* suView, FW_CCloneInfo* cloneInfo)
  418. {
  419.     FW_ASSERT(fPart->IsValidDisplayFrame(ev, fContainingFrameID));
  420.  
  421.     // We only externalize frame that have a persistent containing Frame
  422.     FW_Boolean externalize = GetContainingFrame(ev)->IsPersistent(ev);
  423.  
  424.     ODStorageUnitID frameID = fFrameID;
  425.  
  426.     if (cloneInfo != NULL)
  427.     {
  428.         if (cloneInfo->GetScopeFrame(ev) != NULL)
  429.             externalize = (cloneInfo->GetScopeFrame(ev)->GetID(ev) == fContainingFrameID);
  430.         
  431.         if (externalize)
  432.             frameID = cloneInfo->Clone(ev, fFrameID, 0, fFrameID);
  433.     }
  434.     
  435.     if (externalize)
  436.     {
  437.         // ----- Write out the embedded frame reference -----
  438.         ODStorageUnitRef aSURef;
  439.         FW_CByteArray byteArray(&aSURef, sizeof(ODStorageUnitRef));
  440.          suView->GetStrongStorageUnitRef(ev, frameID, aSURef);
  441.         suView->SetValue(ev, byteArray);
  442.     }
  443.     
  444.     return externalize;
  445. }
  446.  
  447. //----------------------------------------------------------------------------------------
  448. //    FW_CProxyFrame::SetProxy
  449. //----------------------------------------------------------------------------------------
  450.  
  451. void FW_CProxyFrame::SetProxy(Environment* ev, FW_MProxy* proxy)
  452. {
  453. FW_UNUSED(ev);
  454.     FW_ASSERT(fProxy == NULL || proxy == NULL || fProxy == proxy);
  455.     fProxy = proxy;
  456. }
  457.  
  458. //----------------------------------------------------------------------------------------
  459. //    FW_CProxyFrame::SetContainingFrame
  460. //----------------------------------------------------------------------------------------
  461. // We can't change the containing frame is this proxyframe is not orphaned
  462.  
  463. void FW_CProxyFrame::SetContainingFrame(Environment* ev, FW_CEmbeddingFrame* containingFrame)
  464. {
  465.     FW_ASSERT(IsOrphan(ev));
  466.     ODFrame* embeddedFrame = GetFrame(ev);    // Need to bring it into memory
  467.         
  468.     embeddedFrame->SetContainingFrame(ev, containingFrame->GetODFrame(ev));
  469.     fContainingFrameID = containingFrame->GetID(ev);
  470.  
  471.     
  472.     // Not safe to set link status before we have a containing frame, so do it now.
  473.     if (this->IsAttached(ev))
  474.         this->PrivChangeLinkStatus(ev);
  475. }
  476.  
  477. //----------------------------------------------------------------------------------------
  478. //    FW_CProxyFrame::PrivAttach
  479. //----------------------------------------------------------------------------------------
  480.  
  481. void FW_CProxyFrame::PrivAttach(Environment* ev)
  482. {
  483.     FW_CEmbeddingFrame* embeddingFrame = GetContainingFrame(ev);
  484.     if (embeddingFrame != NULL && !fAttached)
  485.     {
  486.         // [HLX] I have to load the frame. Is this a problem?
  487.         ODFrame* odEmbeddedFrame = GetFrame(ev);
  488.     
  489.         odEmbeddedFrame->SetContainingFrame(ev, embeddingFrame->GetODFrame(ev));
  490.         odEmbeddedFrame->SetInLimbo(ev, FALSE);
  491.         
  492.         // ----- It is now attached -----
  493.         fAttached = TRUE;
  494.     
  495.         // ----- Create the facets -----
  496.         CreateAllFacets(ev);
  497.         
  498.         // ----- Set link status if frame is not an orphan ----
  499.         if (!this->IsOrphan(ev))
  500.             this->PrivChangeLinkStatus(ev);
  501.         
  502.     }
  503. }
  504.  
  505. //----------------------------------------------------------------------------------------
  506. //    FW_CProxyFrame::PrivDetach
  507. //----------------------------------------------------------------------------------------
  508.  
  509. void FW_CProxyFrame::PrivDetach(Environment* ev)
  510. {
  511.     FW_CEmbeddingFrame* embeddingFrame = GetContainingFrame(ev);
  512.     if (embeddingFrame != NULL && fAttached)
  513.     {
  514.         this->RemoveAllFacets(ev);
  515.     
  516.         // [HLX] I have to load the frame. Is this a problem?
  517.         ODFrame* odEmbeddedFrame = GetFrame(ev);
  518.             
  519.         // ----- Set the containing frame to null -----
  520.         FW_CAcquiredODFrame aqODContainingFrame = odEmbeddedFrame->AcquireContainingFrame(ev);
  521.         if (aqODContainingFrame == NULL || aqODContainingFrame == embeddingFrame->GetODFrame(ev))
  522.         {
  523.             odEmbeddedFrame->SetInLimbo(ev, TRUE);
  524.             odEmbeddedFrame->SetContainingFrame(ev, NULL);
  525.         }
  526.                 
  527.         // ----- It is now detached -----
  528.         fAttached = FALSE;
  529.     }
  530. }
  531.  
  532. //----------------------------------------------------------------------------------------
  533. //    FW_CProxyFrame::RemoveAllFacets
  534. //----------------------------------------------------------------------------------------
  535. //    Remove all the facets of this proxyframe
  536.  
  537. void FW_CProxyFrame::RemoveAllFacets(Environment* ev)
  538. {
  539.     if (fFacetCount != 0)
  540.     {
  541.         FW_CEmbeddingFrame* embeddingFrame = GetContainingFrame(ev);
  542.         
  543.         if (embeddingFrame && this->IsFrameInMemory(ev))
  544.         {
  545.             FW_CFrameFacetIterator ite(ev, embeddingFrame);
  546.             for (ODFacet* facet = ite.First(ev); ite.IsNotComplete(ev); facet = ite.Next(ev))
  547.                 this->RemoveFacets(ev, embeddingFrame, facet);
  548.         }
  549.     }
  550. }
  551.  
  552. //----------------------------------------------------------------------------------------
  553. //    FW_CProxyFrame::RemoveFacets
  554. //----------------------------------------------------------------------------------------
  555. //    Remove all the facet embedded in embeddingFacet
  556.  
  557. void FW_CProxyFrame::RemoveFacets(Environment* ev, FW_CEmbeddingFrame* frame, ODFacet* embeddingFacet)
  558. {
  559. #ifndef FW_DEBUG
  560. FW_UNUSED(frame);
  561. #endif
  562.  
  563.     FW_ASSERT(frame != NULL);
  564.     FW_ASSERT(embeddingFacet != NULL);
  565.     
  566.     ODFrame* embeddedFrame = this->GetFrame(ev);
  567.     
  568.     FW_TOrderedCollection<ODFacet> tempCollect;
  569.  
  570.     // Attention: Do not try to iterate through all the facets of the embedded frame because
  571.     //    if we are in a middle of a drag&drop, the embedded frame may already have been stripped
  572.     //    of all its facets (in the case where the frame is reused, SetContainingFrame is called
  573.     //    which remove all the facets of the frame). But the hierarchy of facets is still there
  574.     FW_CFacetIterator ite(ev, embeddingFacet, kODChildrenOnly, kODFrontToBack);
  575.     ODFacet* facet;
  576.     for (facet = ite.First(ev); ite.IsNotComplete(ev); facet = ite.Next(ev))
  577.     {
  578.         if (facet->GetFrame(ev) == embeddedFrame)
  579.             tempCollect.AddLast(facet);
  580.     }
  581.     
  582.     FW_TOrderedCollectionIterator<ODFacet> ite2(&tempCollect);
  583.     for (facet = ite2.First(); ite2.IsNotComplete(); facet = ite2.Next())
  584.     {
  585.         fProxy->PrivEmbeddedFacetRemoved(ev);        // Notify proxy
  586.         
  587.         embeddingFacet->RemoveFacet(ev, facet);
  588.         fFacetCount--;
  589.         delete facet;
  590.     }
  591.     
  592.     FW_ASSERT(fFacetCount >= 0);
  593.     
  594.     // RemoveAll will be called by the destructor of tempCollect 
  595.     // tempCollect.RemoveAll();
  596. }
  597.  
  598. //----------------------------------------------------------------------------------------
  599. //    FW_CProxyFrame::PrivNeedFacets
  600. //----------------------------------------------------------------------------------------
  601.  
  602. FW_Boolean FW_CProxyFrame::PrivNeedFacets(Environment* ev, FW_CEmbeddingFrame* embeddingFrame)
  603. {            
  604.     return fProxy->IsShown(ev) &&                                // Proxy is in shown state
  605.             embeddingFrame->GetViewType(ev) == FW_CPart::fgViewAsFrameToken && // Embedding frame is in frame state
  606.             fProxy->NeedFacets(ev, embeddingFrame);                // the proxy is visible
  607. }
  608.  
  609. //----------------------------------------------------------------------------------------
  610. //    FW_CEmbeddingFrame::CreateAllFacets
  611. //----------------------------------------------------------------------------------------
  612.  
  613. FW_DECLARE_THROW_POINT (FW_CProxyFrame_CreateAllFacets);
  614.  
  615. void FW_CProxyFrame::CreateAllFacets(Environment* ev)                                        
  616. {            
  617.     FW_CEmbeddingFrame* embeddingFrame = GetContainingFrame(ev);
  618.     FW_ASSERT(embeddingFrame);
  619.  
  620.     if ((fFacetCount == 0) && PrivNeedFacets(ev, embeddingFrame))
  621.     {        
  622.         FW_CFrameFacetIterator ite(ev, embeddingFrame);
  623.         // Exception Handling: as with all loops, if one pass fails we need to undo the 
  624.         // effects of the previous ones.
  625.         FW_TRY 
  626.         {
  627.             for (ODFacet* containingFacet = ite.First(ev); ite.IsNotComplete(ev); containingFacet = ite.Next(ev))
  628.             {
  629.                 PrivCreateFacets(ev, embeddingFrame, containingFacet);
  630.                 
  631.                 // Testing: what happens if one facet is created and then we fail? (as 
  632.                 // if we tried and failed to create two facets?)
  633.                 FW_CHECK_THROW_POINT (FW_CProxyFrame_CreateAllFacets);
  634.             }
  635.         }
  636.         FW_CATCH_BEGIN
  637.         FW_CATCH_EVERYTHING () 
  638.         {
  639.             RemoveAllFacets(ev);
  640.             FW_THROW_SAME ();
  641.         }
  642.         FW_CATCH_END
  643.     }
  644. }
  645.  
  646. //----------------------------------------------------------------------------------------
  647. //    FW_CProxyFrame::CreateFacets
  648. //----------------------------------------------------------------------------------------
  649.  
  650. void FW_CProxyFrame::CreateFacets(Environment* ev, FW_CEmbeddingFrame* embeddingFrame, ODFacet* embeddingFacet)                                        
  651. {
  652.     if (PrivNeedFacets(ev, embeddingFrame))
  653.         PrivCreateFacets(ev, embeddingFrame, embeddingFacet);
  654. }
  655.  
  656. //----------------------------------------------------------------------------------------
  657. //    FW_CProxyFrame::PrivCreateFacets
  658. //----------------------------------------------------------------------------------------
  659.  
  660. void FW_CProxyFrame::PrivCreateFacets(Environment* ev, FW_CEmbeddingFrame* embeddingFrame, ODFacet* embeddingFacet)
  661. {
  662.     FW_ASSERT(embeddingFacet);
  663.     
  664.     ODFrame* embeddedFrame = this->GetFrame(ev);
  665.     
  666.     FW_CAcquiredODShape proposedClipShape = FW_CopyAndRelease(ev, embeddedFrame->AcquireFrameShape(ev, NULL));
  667.  
  668. #ifdef FW_DEBUG
  669.     unsigned short totalCount =fProxy-> PrivGetEmbeddedFacetCount(ev);
  670. #endif
  671.     
  672.     unsigned short nbFacet = fProxy->CreateFacets(ev, embeddingFrame, embeddingFacet, embeddedFrame, proposedClipShape);
  673.  
  674. #ifdef FW_DEBUG
  675.     // I want to make sure that people use FW_MProxy::CreateFacet instead of ODFacet::CreateEmbeddedFacet
  676.     if (totalCount + nbFacet != fProxy->PrivGetEmbeddedFacetCount(ev))
  677.         FW_DEBUG_MESSAGE("FW_MProxy::CreateFacets must call FW_MProxy::CreateFacet not ODFacet::CreateEmbeddedFacet");
  678. #endif
  679.  
  680.     fFacetCount += nbFacet;
  681. }
  682.  
  683. //----------------------------------------------------------------------------------------
  684. //    FW_CProxyFrame::PrivSetFrameGroup
  685. //----------------------------------------------------------------------------------------
  686.  
  687. void FW_CProxyFrame::PrivSetFrameGroup(Environment* ev, ODID frameGroup)
  688. {
  689.     GetFrame(ev)->SetFrameGroup(ev, frameGroup);
  690. }
  691.  
  692. //----------------------------------------------------------------------------------------
  693. //    FW_CProxyFrame::PrivChangeSequenceNumber
  694. //----------------------------------------------------------------------------------------
  695.  
  696. void FW_CProxyFrame::PrivChangeSequenceNumber(Environment* ev, ODID sequenceNumber)
  697. {
  698.     GetFrame(ev)->ChangeSequenceNumber(ev, sequenceNumber);
  699. }
  700.  
  701. //----------------------------------------------------------------------------------------
  702. //    FW_CProxyFrame::PrivSetDragging
  703. //----------------------------------------------------------------------------------------
  704. // call by FW_CEmbeddingFrame::PrivDragging
  705.  
  706. void FW_CProxyFrame::PrivSetDragging(Environment* ev, FW_EPrivDraggingFlags dragFlags)
  707. {
  708.     //     I only change the dragState of the embedded frame if
  709.     //    change to TRUE : I am selected (fProxy->GetSelectState(ev) == TRUE)
  710.     //    change to FALSE : I was dragged (fWasDragged == TRUE)
  711.     
  712.     FW_Boolean dragStart = (dragFlags == FW_kStartDrag);
  713.     if (dragStart ? fProxy->GetSelectState(ev) : fWasDragged)
  714.     {
  715.         if (dragStart)
  716.             GetFrame(ev)->SetInLimbo(ev, TRUE);        // set the embedded frame to in limbo
  717.         else if (dragFlags == FW_kDragAborted || dragFlags == FW_kDragCopy)
  718.             GetFrame(ev)->SetInLimbo(ev, FALSE);    // put back the frame not in limbo
  719.                 
  720.         // Change the Drag state of all the proxyframes of fProxy
  721.         FW_CProxyProxyFrameIterator iter(fProxy);
  722.         for (FW_CProxyFrame* proxyFrame = iter.First(); iter.IsNotComplete(); proxyFrame = iter.Next())
  723.         {
  724.             if (proxyFrame->IsFrameInMemory(ev))
  725.                 proxyFrame->GetFrame(ev)->SetDragging(ev, dragStart);
  726.         }
  727.         
  728.         fWasDragged = dragStart;
  729.     }
  730.     else
  731.         fWasDragged = FALSE;
  732. }
  733.  
  734. //----------------------------------------------------------------------------------------
  735. //    FW_CProxyFrame::ChangeHighlight
  736. //----------------------------------------------------------------------------------------
  737.  
  738. void FW_CProxyFrame::ChangeHighlight(Environment* ev, ODHighlight highlight)
  739. {
  740.     if (IsFrameInMemory(ev))
  741.     {
  742.         FW_CODFrameFacetIterator ite2(ev, GetFrame(ev));
  743.         for (ODFacet* facet = ite2.First(ev); ite2.IsNotComplete(ev); facet = ite2.Next(ev))
  744.             facet->ChangeHighlight(ev, highlight);
  745.     }
  746.     
  747.     fHighlight = highlight;
  748. }
  749.  
  750. //----------------------------------------------------------------------------------------
  751. //    FW_CProxyFrame::ChangeLinkStatus
  752. //----------------------------------------------------------------------------------------
  753.  
  754. void  FW_CProxyFrame::ChangeLinkStatus(Environment* ev, ODLinkStatus linkStatus)
  755. {
  756.     fLinkStatus = linkStatus;
  757.     
  758.     if (this->IsFrameInMemory(ev) && !this->IsOrphan(ev) && this->IsAttached(ev))
  759.     {
  760.         this->PrivChangeLinkStatus(ev);
  761.     }
  762. }
  763.  
  764.  
  765. //----------------------------------------------------------------------------------------
  766. //    FW_CProxyFrame::PrivChangeLinkStatus
  767. //----------------------------------------------------------------------------------------
  768.  
  769. void  FW_CProxyFrame::PrivChangeLinkStatus(Environment* ev) const
  770. {
  771.     FW_ASSERT(this->IsFrameInMemory(ev));
  772.     FW_ASSERT(this->IsAttached(ev));
  773.     FW_ASSERT(!this->IsOrphan(ev));
  774.     
  775.     ODFrame* embeddedFrame = this->GetFrame(ev);
  776.     
  777.     embeddedFrame->ChangeLinkStatus(ev, fLinkStatus);
  778.     
  779. }
  780.  
  781.  
  782.  
  783.